package jp.ac.aiit.spg;

import javax.servlet.http.HttpSession;

import jp.ac.aiit.spg.common.*;
import jp.ac.aiit.spg.web.login.LoginPage;

public abstract class AbstractSpgPage {

	private HttpSession session;

	public void setSessionScope(HttpSession session) {
		this.session = session;
	}

	public HttpSession getSessionScope() {
		return this.session;
	}

	public void setSessionAttribute(String key, Object value) {
		this.session.setAttribute(key, value);
	}

	public void removeSessionAttribute(String key) {
		this.session.removeAttribute(key);
	}

	public boolean isLoggedIn() {

		if ((Boolean) this.session.getAttribute(SpgConstant.SESSION_BIND_LOGIN_STATUS) != null) {
			return (Boolean) this.session.getAttribute(SpgConstant.SESSION_BIND_LOGIN_STATUS);
		} else {
			return false;
		}
	}

	public int getLoginUserId() {

		return (Integer) this.session.getAttribute(SpgConstant.SESSION_BIND_LOGIN_USERID);

	}

	public Class logout() {
		removeSessionAttribute(SpgConstant.SESSION_BIND_LOGIN_STATUS);
		removeSessionAttribute(SpgConstant.SESSION_BIND_LOGIN_USERID);
		return LoginPage.class;

	}

}
